public class SearchMatrix {
    // leetcode 搜索二维矩阵II
    // https://leetcode.cn/problems/search-a-2d-matrix-ii/description/?envType=study-plan-v2&envId=top-100-liked
    public boolean searchMatrix(int[][] matrix, int target) {
        int len1 = matrix.length, len2 = matrix[0].length;
        int x = 0, y = len2-1;
        while (x < len1 && y >= 0) {
            if (matrix[x][y] == target) return true;
            else if (matrix[x][y] < target) x++;
            else {
                y--;
            }
        }
        return false;
    }
}
